package com.bmob.lover.ui.fragment

import android.view.KeyEvent
import android.view.View
import androidx.viewpager.widget.ViewPager
import com.qmuiteam.qmui.arch.QMUIFragment
import com.qmuiteam.qmui.widget.tab.QMUITabBuilder
import com.bmob.lover.R
import com.bmob.lover.ui.fragment.album.AlbumFragment
import com.bmob.lover.ui.fragment.cost.CostFragment
import com.bmob.lover.ui.fragment.lover.LoverFragment
import com.theone.mvvm.base.viewmodel.BaseViewModel
import com.theone.mvvm.core.base.fragment.BaseTabIndexFragment
import com.theone.mvvm.core.app.ext.qmui.addTab
import com.theone.mvvm.core.data.entity.QMUIItemBean

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 * @author The one
 * @date 2021-04-19 13:52
 * @describe TODO
 * @email 625805189@qq.com
 * @remark
 */
class IndexFragment:BaseTabIndexFragment<BaseViewModel>(), ViewPager.OnPageChangeListener {

    private var INDEX = 0

    override fun isExitPage(): Boolean  = true

    override fun QMUITabBuilder.applyTabBuilder() {
        skinChangeNormalWithTintColor(true)
    }

    override fun initTabAndFragments(
        tabs: MutableList<QMUIItemBean>,
        fragments: MutableList<QMUIFragment>
    ) {

        with(tabs){
            addTab("动态", R.drawable.ic_index_dynamic)
            addTab("相册", R.drawable.ic_index_album)
            addTab("账本", R.drawable.ic_index_cost)
            addTab("我们", R.drawable.ic_index_we)
        }

        with(fragments){
            add(LoverFragment())
            add(AlbumFragment())
            add(CostFragment())
            add(WeFragment())
        }

    }

    override fun initView(root: View) {
        super.initView(root)
        getViewPager().addOnPageChangeListener(this)
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
//        if (keyCode == KeyEvent.KEYCODE_BACK && INDEX == 0) {
//            val fragment = mPagerAdapter.createFragment(0) as LoverFragment
//            if (fragment.isFull()) {
//                fragment.onBackPressed()
//                return true
//            }
//        }
        return super.onKeyDown(keyCode, event)
    }

    override fun onPageScrollStateChanged(state: Int) {}

    override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}

    override fun onPageSelected(position: Int) {
        INDEX = position
    }


}